package com.ruoyi.peach.mapper;

import java.util.List;

import com.ruoyi.peach.domain.*;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * 文章管理Mapper接口
 * 
 * @author ld
 * @date 2025-04-22
 */
public interface ArticlesMapper 
{
    /**
     * 查询文章管理
     * 
     * @param articleId 文章管理主键
     * @return 文章管理
     */
    public Articles selectArticlesByArticleId(String articleId);

    /**
     * 查询文章管理列表
     * 
     * @param articles 文章管理
     * @return 文章管理集合
     */
    public List<Articles> selectArticlesList(Articles articles);
    public List<Articles> selectArticlesListApp(Articles articles);

    /**
     * 新增文章管理
     * 
     * @param articles 文章管理
     * @return 结果
     */
    public int insertArticles(Articles articles);

    /**
     * 修改文章管理
     * 
     * @param articles 文章管理
     * @return 结果
     */
    public int updateArticles(Articles articles);

    /**
     * 删除文章管理
     * 
     * @param articleId 文章管理主键
     * @return 结果
     */
    public int deleteArticlesByArticleId(String articleId);

    /**
     * 批量删除文章管理
     * 
     * @param articleIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteArticlesByArticleIds(String[] articleIds);
    public int viewCount(String articleId);

    public int likeCount(String articleId);

    public int commentOne(Comment comment);

    public int commentTow(Comment2 comment);

    @Select("SELECT " +
            "u.user_name AS userName, " + // 起别名 userName，对应实体类 userName 属性
            "c.content AS content, " +
            "c.creat_time AS creatTime ," +
            "c.comment_id As commentId "  +// +起别名 creatTime，对应实体类 creatTime 属性
            "FROM comment c " +
            "LEFT JOIN sys_user u ON c.user_id = u.user_id " +
            "WHERE c.article_id = #{articleId}")
    public List<Comment4> electComment1List(String articleId);

    @Select("SELECT " +
            "u.user_name AS userName, " + // 起别名 userName，对应实体类 userName 属性
            "c.content AS content, " +
            "c.creat_time AS creatTime " + // 起别名 creatTime，对应实体类 creatTime 属性
            "FROM comment2 c " +
            "LEFT JOIN sys_user u ON c.user_id = u.user_id " +
            "WHERE c.comment_id = #{commentId}")
    public List<Comment3> electComment2List(String commentId);

    public void commentOneCount(String articleId);

    public void commentTowCount(String commnetId);
    @Select({
            "select article_id, a.user_id, title, content, image_urls, view_count, like_count, comment_count, created_at, updated_at, nick_name, avatar, hot ",
            "from articles a left join sys_user u on a.user_id = u.user_id ",
            "where a.content like concat('%', #{contents}, '%') ",  // 模糊查询条件
            "order by created_at desc"
    })
    @Results({
            @Result(property = "articleId", column = "article_id"),       // 数据库article_id → 类articleId
            @Result(property = "userId", column = "user_id"),             // 数据库user_id → 类userId
            @Result(property = "title", column = "title"),
            @Result(property = "content", column = "content"),
            @Result(property = "imageUrls", column = "image_urls"),       // 数据库image_urls → 类imageUrls
            @Result(property = "viewCount", column = "view_count"),       // 数据库view_count → 类viewCount
            @Result(property = "likeCount", column = "like_count"),       // 数据库like_count → 类likeCount
            @Result(property = "commentCount", column = "comment_count"), // 数据库comment_count → 类commentCount
            @Result(property = "createdAt", column = "created_at"),       // 数据库created_at → 类createdAt（Date类型）
            @Result(property = "updatedAt", column = "updated_at"),       // 数据库updated_at → 类updatedAt（Date类型）
            @Result(property = "hot", column = "hot")
            // 注：sys_user表的nick_name、avatar若需映射到Articles类，需在Articles中添加对应属性，再补充@Result映射
    })
    public List<Articles> GetBy(String contents);
    @Select("SELECT user_name FROM sys_user WHERE user_id = #{userId}")
    public String getusername(Long userId);

}
